$(function () {
	// 表单验证
	$("form").on("submit", function (event) {
		event.preventDefault(); // 阻止表单默认提交

		var username = $(".username").val();
		var password = $(".password").val();
		var rpassword = $(".rpassword").val();
		var nickname = $(".nickname").val();
		console.log(password, rpassword);

		// 简易的前端表单验证示例，实际项目中可能需要更复杂的验证逻辑
		if (!username || !password || !rpassword || !nickname) {
			alert("请填写所有必填项");
			return false;
		}
		if (password !== rpassword) {
			alert("两次密码不一致");
			return false;
		}

		// 发送注册请求
		axios
			.post("http://localhost:9000/users/register", {
				username: username,
				password: password,
				rpassword: rpassword,
				nickname: nickname,
			})
			.then(function (response) {
				if (response.data.code === 1) {
					alert(response.data.message);
					window.location.href = "./login.html";
				} else {
					alert(response.data.message);
				}
			})
			.catch(function (error) {
				alert("请求出错");
			});
	});
});
